// 静态生命周期  'static 意味着能和程序活得一样久，例如字符串字面量和特征对象

struct ImportantExcerpt<'a> {
    part: &'a str,
}

impl<'a> ImportantExcerpt<'a> {
    fn level(&self) -> i32 {
        3
    }
    fn announce_and_return_part(&self, announcement: &str) -> &str {
        println!("Attention please: {}", announcement);
        self.part
    }
}
/*
1--> 编译器应用第一规则，给予每个输入参数一个生命周期
impl<'a> ImportantExcerpt<'a> {
    fn announce_and_return_part<'b>(&'a self, announcement: &'b str) -> &str {
        println!("Attention please: {}", announcement);
        self.part
    }
}

2-->编译器应用第三规则，将 &self 的生命周期赋给返回值 &str
impl<'a> ImportantExcerpt<'a> {
    fn announce_and_return_part<'b>(&'a self, announcement: &'b str) -> &'a str {
        println!("Attention please: {}", announcement);
        self.part
    }
}

单独开一个 'a 生命周期： err 编译器会报错，因为编译器无法知道 'a 和 'b 的关系
impl<'a> ImportantExcerpt<'a> {
    fn announce_and_return_part<'b>(&'a self, announcement: &'b str) -> &'b str {
        println!("Attention please: {}", announcement);
        self.part
    }
}


'a: 'b，是生命周期约束语法，跟泛型约束非常相似，用于说明 'a 必须比 'b 活得久
可以把 'a 和 'b 都在同一个地方声明（如上），或者分开声明但通过 where 'a: 'b 约束生命周期关系，如下：


// impl<'a: 'b, 'b> ImportantExcerpt<'a> { 普通声明

impl<'a> ImportantExcerpt<'a> {
    fn announce_and_return_part<'b>(&'a self, announcement: &'b str) -> &'b str
    where
        'a: 'b, // where 子句
    {
        println!("Attention please: {}", announcement);
        self.part
    }
}

*/
#[cfg(test)]
mod static_life {
    use crate::basex::lifecycle::structx::ImportantExcerpt;

    #[test]
    fn main() {
        ImportantExcerpt { part: "aa" };
    }
}
